package com.zz.hhbl

import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import com.shuyu.gsyvideoplayer.cache.CacheFactory
import com.shuyu.gsyvideoplayer.cache.ProxyCacheManager
import com.shuyu.gsyvideoplayer.player.IjkPlayerManager
import com.shuyu.gsyvideoplayer.player.PlayerFactory
import com.tencent.bugly.crashreport.CrashReport
import com.zz.framework.core.BaseApp
import com.zz.framework.core.ext.dp
import com.zz.framework.core.ext.print
import com.zz.framework.core.utils.ActivityStackManager
import com.zz.framework.core.utils.LogUtils
import com.zz.hhbl.receiver.ChargingReceiver
import com.zz.hhbl.ui.LaunchActivity
import dagger.hilt.android.HiltAndroidApp
import kotlin.properties.Delegates


/**
 * Copyright © 2025 zhun All rights reserved.
 * Created by ZhaoZhun on 2025/2/17 21:18.
 * @author: ZhaoZhun 1820022519@qq.com
 * @version: V1.0
 */
@HiltAndroidApp
class App : BaseApp() {
    private var chargingReceiver: ChargingReceiver = ChargingReceiver()
    companion object {
        private var _context: App by Delegates.notNull()
        @JvmStatic
        fun getContext(): App {
            return _context
        }
    }
    override fun onCreate() {
        super.onCreate()
        _context = this
        //ijk内核，默认模式
        PlayerFactory.setPlayManager(IjkPlayerManager::class.java)
        //代理缓存模式，支持所有模式，不支持m3u8等，默认
        CacheFactory.setCacheManager(ProxyCacheManager::class.java)
        registerChargingReceiver()
        ActivityStackManager.instance.setMainActivity(LaunchActivity::class.java)
        CrashReport.initCrashReport(applicationContext, "2b5a20fb8b", false);
    }

    private fun registerChargingReceiver() {
        val intentFilter = IntentFilter().apply {
            addAction(Intent.ACTION_POWER_CONNECTED)
            addAction(Intent.ACTION_POWER_DISCONNECTED)
            addAction(Intent.ACTION_BATTERY_CHANGED)
        }
        registerReceiver(chargingReceiver, intentFilter)
    }

    private fun unregisterChargingReceiver() {
        unregisterReceiver(chargingReceiver)
    }

//    override fun onTerminate() {
//        super.onTerminate()
//        unregisterChargingReceiver()
//    }
}